/**
 * 
 */
package com.nh.action;

import java.sql.Timestamp;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.nh.entity.NgAdmin;
import com.nh.entity.NgNewsCategory;

/**
 * 项目名称：NotoginsengManage
 * 
 * 类名称：NewsCategoryAction
 * 
 * 类描述： 信息分类
 * 
 * 创建人：李兴建
 * 
 * E-mail:lxj08193@163.com
 * 
 * 创建时间：2012-11-2 下午06:54:29
 * 
 * 修改人：李兴建
 * 
 * 修改时间：2012-11-2 下午06:54:29
 * 
 * 修改备注：
 * 
 * @version
 */
public class NewsCategoryAction extends BaseAction {
	private List<NgNewsCategory> newsCategoryList;
	private NgNewsCategory newsCategory;
	private Long optionId;

	/**
	 * 列表
	 * 
	 * @return
	 */
	public String newsCategoryList() {
		newsCategoryList = this.getBaseService().findAll(NgNewsCategory.class, "oder", "ASC");
		return "newsCategoryList";
	}

	/**
	 * 添加页面
	 * 
	 * @return
	 */
	public String newsCategoryAddPage() {
		newsCategory = new NgNewsCategory();
		newsCategory.setState(0);
		newsCategory.setOder(10);
		return "newsCategoryAddPage";
	}

	/**
	 * 添加保存
	 * 
	 * @return
	 */
	public String newsCategoryAddSave() {
		if (StringUtils.isEmpty(newsCategory.getTitle())) {
			this.addFieldError("titleError", "分类标题格式不正确");
			return "newsCategoryAddPage";
		}
		newsCategory.setCreateAdminid("");
		newsCategory.setCreateTime(new Timestamp(System.currentTimeMillis()));
		this.getBaseService().save(newsCategory);
		return newsCategoryList();
	}

	/**
	 * 修改页面
	 * 
	 * @return
	 */
	public String newsCategoryModifyPage() {
		newsCategory = this.getBaseService().findById(optionId, NgNewsCategory.class);
		return "newsCategoryModifyPage";
	}

	/**
	 * 修改保存
	 * 
	 * @return
	 */
	public String newsCategoryModifySave() {
		if (StringUtils.isEmpty(newsCategory.getTitle())) {
			this.addFieldError("titleError", "分类标题格式不正确");
			return "newsCategoryAddPage";
		}
		this.getBaseService().saveOrUpdate(newsCategory, NgNewsCategory.class);
		return newsCategoryList();
	}

	/**
	 * 停用
	 * 
	 * @return
	 */
	public String stopCategory() {
		newsCategory = this.getBaseService().findById(optionId, NgNewsCategory.class);
		if (newsCategory.getState() == 0) {
			newsCategory.setState(1);
			this.getBaseService().saveOrUpdate(newsCategory, NgNewsCategory.class);
		}
		return newsCategoryList();
	}

	/**
	 * 启用
	 * 
	 * @return
	 */
	public String startCategory() {
		newsCategory = this.getBaseService().findById(optionId, NgNewsCategory.class);
		if (newsCategory.getState() == 1) {
			newsCategory.setState(0);
			this.getBaseService().saveOrUpdate(newsCategory, NgNewsCategory.class);
		}
		return newsCategoryList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 */
	public String remove() {
		newsCategory = this.getBaseService().findById(optionId, NgNewsCategory.class);
		newsCategory.setState(2);
		this.getBaseService().saveOrUpdate(newsCategory, NgNewsCategory.class);
		return newsCategoryList();
	}

	/**
	 * 恢复
	 * 
	 * @return
	 */
	public String reRemove() {
		newsCategory = this.getBaseService().findById(optionId, NgNewsCategory.class);
		if (newsCategory.getState() == 2) {
			newsCategory.setState(0);
			this.getBaseService().saveOrUpdate(newsCategory, NgNewsCategory.class);
		}
		return newsCategoryList();
	}

	/**
	 * @return the newsCategoryList
	 */
	public List<NgNewsCategory> getNewsCategoryList() {
		return newsCategoryList;
	}

	/**
	 * @param newsCategoryList
	 *            the newsCategoryList to set
	 */
	public void setNewsCategoryList(List<NgNewsCategory> newsCategoryList) {
		this.newsCategoryList = newsCategoryList;
	}

	/**
	 * @return the newsCategory
	 */
	public NgNewsCategory getNewsCategory() {
		return newsCategory;
	}

	/**
	 * @param newsCategory
	 *            the newsCategory to set
	 */
	public void setNewsCategory(NgNewsCategory newsCategory) {
		this.newsCategory = newsCategory;
	}

	/**
	 * @return the optionId
	 */
	public Long getOptionId() {
		return optionId;
	}

	/**
	 * @param optionId
	 *            the optionId to set
	 */
	public void setOptionId(Long optionId) {
		this.optionId = optionId;
	}
}
